﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Core.Web;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using FineUIPro;

namespace CanDoo.Oil.WebApp.UserControls
{
    public partial class SelectProduct : UserControlBase<IProductContract, Product>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SelectProductControl_GridList.EnableMultiSelect = EnableMultiSelect;
                SelectProductControl_GridList.KeepCurrentSelection = EnableMultiSelect;
                InitGrid();
            }
        }

        protected override void InitControls()
        {
            this._GridList = SelectProductControl_GridList;
            this._SearchKey = SearchKey;
        }

        protected override void SetSelector()
        {
            this.Selector = p => new
            {
                p.SN,
                p.Code,
                p.ShortName,
                p.ProductType,
                p.ProductTypeId,
                p.Brand,
                p.BrandId,
                p.DefaultSupplier,
                p.DefaultSupplierId,
                p.ProductUnit,
                p.ProductUnitId,
                p.Specifications,
                p.Model,
                p.Weight,
                p.Unit,
                p.ImgUrl1,
                p.ImgUrl2,
                p.ImgUrl3,
                p.ImgUrl4,
                p.ImgUrl5,
                p.Year,
                p.MarketTime,
                p.Outline,
                p.Explain,
                p.TechnicalParameter,
                p.CommonProblem,
                p.Remark,
                p.MarkedPrice,
                p.DefaultCostPrice,
                p.RetailPrice,
                p.VIPPrice1,
                p.VIPPrice2,
                p.VIPPrice3,
                p.VIPPrice4,
                p.TradePrice1,
                p.TradePrice2,
                p.TradePrice3,
                p.TradePrice4,
                p.TradePrice5,
                p.TradePrice6,
                p.TradePrice7,
                p.TradePrice8,
                p.FocusTracking,
                p.IsNew,
                p.EasyStock,
                p.ProductClass,
                p.ExchangeIntegral,
                p.FrontDesk,
                p.NoIntegral,
                p.NoDiscount,
                p.Enable,
                p.ManageSerialNum,
                p.Id,
                p.Name
            };
        }


        protected override void Search()
        {
            var key = SearchKey.GetValue();
            if(key.IsNullOrEmpty() == false)
            {
                Filter = Filter.And(p => p.Name.Contains(key));
            }
            //base.Search();
        }
    }
}

